﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Unity.Game.ElisAdvance.ElisScript
{
    public class ElisState_Attack
    {
        public static void onProc(ElisActiveObject activeObject)
        {

            if (activeObject.getAttackIndex() == 0)
            {
                float aniTime = activeObject.getAniManager().getAniTime();
                if (aniTime > 0.8f)
                {
                    activeObject.setState(State.STATE_STAND);
                }
                else
                {

                    if (aniTime > 0.2f && aniTime < 0.25f)
                    {
                        AttackObjectTempVector damageList = activeObject.getAttackInfo().onInAreaAttack(-0.75f, 0f, 2.25f, 1.0f);
                        if (damageList.sendHit(activeObject, 1.0f, DamageBounsType.PUSH, 1.0f, 2.0f, 1.5f))
                        {
                            //activeObject.setPause(1.0f);
                        }
                    }

                }

            }else if (activeObject.getAttackIndex() == 1)
            {

                float aniTime = activeObject.getAniManager().getAniTime();
                
                if (aniTime > 0.95f)
                {
                    activeObject.setState(State.STATE_STAND);
                }
                else
                {

                    if (aniTime > 0.4f && aniTime < 0.5f)
                    {
                        AttackObjectTempVector damageList = activeObject.getAttackInfo().onInAreaAttack(-0.25f, 0f, 2f, 1.0f);
                        if (damageList.sendHit(activeObject, 1.0f, DamageBounsType.PUSH, 4.0f, -2.0f, 1.5f))
                        {
                            //activeObject.setPause(1.0f);
                        }
                    }

                }

            }
        }

        public static void onFixedProc(ElisActiveObject activeObject, float horiztantlKey)
        {
            if (activeObject.getAttackIndex() == 0)
            {

                float aniTime = activeObject.getAniManager().getAniTime();

                if (aniTime > 0.4f)
                {
                    if (KeyPressEvent.isKeyPressDownAttack())
                    {
                        activeObject.clearStateVector();
                        activeObject.pushStateVector(1);
                        activeObject.setState(State.STATE_ATTACK);
                    }
                    else if (KeyPressEvent.isKeyPressDownDash())
                    {
                        activeObject.clearStateVector();
                        activeObject.pushStateVector(0);
                        activeObject.setState(State.STATE_DASH);
                    }
                }
            }
            else if (activeObject.getAttackIndex() == 1)
            { 
            }
        }

        public static void onSetState(ElisActiveObject activeObject)
        {
            activeObject.getGravityEvent().setEnable(false);
            if (activeObject.getAttackIndex() == 0)
            {
                activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
                activeObject.getAniManager().setAni("Attack");
                activeObject.getAniManager().setAni("AttackType", 0);
                activeObject.getAniManager().setAniSpeed(1.5f);
                activeObject.getAttackInfo().setEnable(true, "OBJECT");

            }
            else if (activeObject.getAttackIndex() == 1)
            {
                activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
                activeObject.getAniManager().setAni("Attack");
                activeObject.getAniManager().setAni("AttackType", 1);
                activeObject.getAniManager().setAniSpeed(1.5f);
                activeObject.getAttackInfo().setEnable(true, "OBJECT");



            }
        }

        public static void onEndState(ElisActiveObject obj, State state)
        {
            if (state != State.STATE_DASH)
            {
                obj.setXVelocity(0);
            }

        }

    }
}

//玩家elis引入事件
